<?php 
namespace Admin\Controller;
use Think\Controller;
class AttributeController extends CommonController{
	//属性列表
	public function index(){
		$this->attr = M('attr')->select();
		$this->display();
	}
	//添加属性 
	public function addAttr(){
		$this->display();
	}
	//添加属性处理表单
	public function addAttrHandle(){
		if(!IS_POST) $this->error("提交方式错误");
		if(M('attr')->add(I())){
			$this->success("添加成功");
		}else{
			$this->error("添加失败");
		}
	}
	//删除属性处理表单
	public function delAttrHandle(){
		if(!IS_POST) $this->error("提交方式错误");
		if(M('attr')->where(array("id"=>I('id')))->delete()){
			$this->success("属性删除成功");
		}else{

			$this->error("属性删除失败!");
		}
	}
	//更新属性信息
	public function updateAttr(){
	//	p(I());die;
		$this->name =I('name');
		$this->color=I('color');
		$this->id=I("id");
		$this->display();
	}
	//更新属性处理表单
	public function updateAttrHandle(){
		if(!IS_POST) $this->error("提交方式错误");
		$id = I('id','','intval');
		$data = array('name'=>I('name'),'color'=>I('color'));
		$result = M('attr')->where(array('id'=>$id))->save($data);
		if($result){
			$this->success("字段更新成功");
		}else{
			$this->error("字段更新失败");
		}
	}

}